$(function () {
  
    var lawId= getQueryString("lawId");
    console.log(lawId);
    //根据id从数据库中获取修改前的值
    $.post(
        "/citrusmonitor/law.do?method=findById&lawId="+lawId,

        function (data) {
         $("#lawId").val(data.lawId),
	     $("#tittle").val(data.tittle),
	     $("#source").val(data.source),
         $("#content").val(data.content),
    /*     $("#publish_time").val(data.publishTime),*/
	     $("#file_path").val(data.filePath)
        },
        "json"
    );
    //edit按钮绑定事件
    $("#edit").click(function () {

 	 var formData = new FormData(); 
 	formData.set("lawId",$("#lawId").val());
   		formData.set("tittle",$("#tittle").val());
   		formData.set("source",$("#source").val());
   	/*	formData.set("publishTime",$("#publish_time").val());*/
   		formData.set("content",$("#content").val());
   		formData.set("filePath", document.getElementById("file_path").files[0]);
//   		formData.set("imgPath",$("#img_path").val());
   	    $.ajax({
   	        url: "/citrusmonitor/law.do?method=modify",
   	        type: "post",
   	        data:formData, 
   	        processData:false, 
   	        contentType:false, 
  
/*
        $.post(
            "/citrusmonitor/law.do?method=modify",
            {
            	"lawId": $("#law_id").val(),
                "tittle": $("#tittle").val(),
                "source": $("#source").val(),
                "content": $("#content").val(),
                "publishTime": $("#publish_time").val(),
                "filePath": $("#file_path").val()
            },*/
            dataType: "json",
	        success: function (msg) {
	        	console.log(msg)
	            if (msg.status==1) {
	                alert("修改信息成功");
	                window.location.href="show.html";
	            } else {
	                alert("修改信息失败" );
	            }
	        },
	        error:function(){
	            alert("资源加载失败！！！");
	        }
	    })

})
})
   	
   	
   	
function getQueryString(name) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");

    var r = window.parent.document.getElementById("rightframe").contentWindow.location.search.substr(1).match(reg);
    if(r!=null){
        return  unescape(r[2]);
    }
    return null;
}
